package datastruct.tree;

/**
 * @Author Gorchun
 * @create 2021/2/26 11:03
 */
public class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode() {}
    public TreeNode(int val) { this.val = val; }

    public TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
    }

    /**
     * 当前节点为根的树的高度
     * @return
     */
    public int height(){
        int leftHeight = left==null?0:left.height();
        int rightHeight = right==null?0:right.height();
        return Math.max(leftHeight,rightHeight)+1;
    }

    /**
     * 左子树高度
     */
    public int leftHeight(){
        int height = left==null?0:left.height();
        return height;
    }

    /**
     * 右子树高度
     */
    public int rightHeight(){
        int height = right==null?0:right.height();
        return height;
    }


}
